<!-- <script type="text/javascript">  
var result=document.getElementById("result");  
var file=document.getElementById("file");  
  
//判断浏览器是否支持FileReader接口  
if(typeof FileReader == 'undefined'){  
    result.InnerHTML="<p>你的浏览器不支持FileReader接口！</p>";  
    //使选择控件不可操作  
    file.setAttribute("disabled","disabled");  
}  
  
function readAsDataURL(){
    //检验是否为图像文件  
    var file = document.getElementById("file").files[0];  
    if(!/image\/\w+/.test(file.type)){  
        alert("看清楚，这个需要图片!");  
        return false;
    }  
    var reader = new FileReader();
    //将文件以Data URL形式读入页面
    reader.readAsDataURL(file);
    reader.onload=function(e){
        var result=document.getElementById("result");  
        //显示文件  
        result.innerHTML='<img src="'+ this.result +'" alt="" />';  
    }  
}  
  
function readAsBinaryString(){  
    var file = document.getElementById("file").files[0];  
    var reader = new FileReader();  
    //将文件以二进制形式读入页面  
    reader.readAsBinaryString(file,"UTF-8");  
    reader.onload=function(f){  
        var result=document.getElementById("result");  
        //显示文件  
        result.innerHTML=this.result;  
    }
}
  
function readAsText(){  
    var file = document.getElementById("file").files[0];  
    var reader = new FileReader();  
    //将文件以文本形式读入页面  
    reader.readAsText(file);  
    reader.onload=function(f){  
        var result=document.getElementById("result");  
        //显示文件  
        result.innerHTML=this.result;  
    }  
}  
</script>  
<p>  
    <label>请选择一个文件：</label>  
    <input type="file" id="file" />  
    <input type="button" value="读取图像" onclick="readAsDataURL()" />  
    <input type="button" value="读取二进制数据" onclick="readAsBinaryString()" />  
    <input type="button" value="读取文本文件" onclick="readAsText()" />  
</p>  
<div id="result" name="result"></div> -->
 <script  type="text/javascript"  charset="utf-8"></script>
 <form   onsubmit="return start();"  method="post" enctype="multipart/form-data">
 <table>
    上传文件 ： <input type="file" name = "file" id = "fileId" /> 
    
     <input type="hidden" name="uploadURL" id = "uploadURL">
      <input type="hidden" name="resultId" id = "resultId">
       <input type="hidden" name="taskUuid" id = "taskUuid">  
    <button  type = "button" name = "btn"  id = "btnId" onclick="check()" > 获取上传地址</button>
     <button id="uploader" onclick="start()"">上传</button> 
    <!--  <input type="submit"  value="上传"/> </td> -->
    <div id="result" name="result"></div>
    </table>
</form>

<script>

    function check() {
        var files = $('#fileId').prop('files');//获取到文件列表
        console.log(files);
        if(files.length == 0){
            alert('请选择文件');
        }else{
            var fileName = files[0].name;
            var array = fileName.split(".");
            var nameStr = array[0];
            var typeStr = "."+array[1];
            var size = files[0].size;
            var getUrl = API_URL+"load_balancer/file_upload_url?AccessToken=AccessTokenString&FileName="+nameStr+"&FileExtName="+typeStr+"&FileSize="+size+"";
             $.ajax({
                            url :getUrl,
                            type: 'GET',
                            success : function(result) {
                            	var upUrl = result.ServiceUrl;
                            	$("#uploadURL").val(upUrl);
                              var resultId = result.Id;
                              $("#resultId").val(resultId);
                              var taskUuid = result.TaskUuid;
                              $("#taskUuid").val(taskUuid);
                            	console.log(result);
                              alert("获取地址成功！");
                             
                            }
                          });
        
    }
    
}
 function start() {

       var files = $('#fileId').prop('files');//获取到文件列表
       
        if(files.length == 0){
            alert('请选择文件');
        }else{
            var file = document.getElementById("fileId").files[0];  
           /* var reader = new FileReader();  
            //将文件以二进制形式读入页面  
            reader.readAsBinaryString(file,'GB2312');  
         
            reader.onload=function(data){  
                var result=document.getElementById("result");  
                //显示文件  
                result.innerHTML=this.result;  
            }  */
              var reader = new FileReader();
                 content = reader.readAsDataURL(file,"UTF-8");

                
                  reader.onload = function(event) {
                    content = event.target.result;
                    console.log("数据"+content)
                }
           
             postUrl = $("#uploadURL").val();
            id = $("#resultId").val();
            taskUuid = $("#taskUuid").val();
            var uplodUrl = postUrl+"?AccessToken=AccessTokenString&Id="+id+"&TaskUuid="+taskUuid+"&FileBeginPos="+0+"&FileEndPos="+99999999; 
               		  /* $.ajax({
                            url :uplodUrl,
                            type: 'POST',
                            data:fileString,
                            success : function(data) {
                              alert("上传成功！");
                             
                            }
                          });*/

                          alert("hh");
		
            }
  
    
}
</script>

<!-- 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
    <title>上传</title>
    
    <style type="text/css">
        table
        {
            font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
            width:100%;
            border-collapse:collapse;
        }

        td, th
        {
            font-size:1em;
            border:1px solid #98bf21;
            padding:3px 7px 2px 7px;
        }

        th
        {
            font-size:1.1em;
            text-align:left;
            padding-top:5px;
            padding-bottom:4px;
            background-color:#A7C942;
            color:#ffffff;
        }

    </style>
<script type="text/javascript">
//这利用的是多个
     function check() {
        var files = $('#file').prop('files');//获取到文件列表
        console.log(files);
        if(files.length == 0){
            alert('请选择文件');
        }else{
            var fileName = files[0].name;
            var array = fileName.split(".");
            var nameStr = array[0];
            var typeStr = "."+array[1];
            var size = files[0].size;
            var getUrl = API_URL+"load_balancer/file_upload_url?AccessToken=AccessTokenString&FileName="+nameStr+"&FileExtName="+typeStr+"&FileSize="+size+"";
             $.ajax({
                url :getUrl,
                type: 'GET',
                success : function(result) {
                    //真正的 上传地址
                    var upUrl = result.ServiceUrl;
                    $("#uploadURL").val(upUrl);
                  var resultId = result.Id;
                  $("#resultId").val(resultId);
                  var taskUuid = result.TaskUuid;
                  $("#taskUuid").val(taskUuid);
                    console.log(result);
                  alert("获取地址成功！");
                 
                }
              });
        
        }
    
    }

    var BYTES_PER_CHUNK = 1024 * 1024; // 每个文件切片大小定为1MB .
    var slices;
    var totalSlices;

//发送请求
function sendRequest() {
    var blob = document.getElementById("file").files[0];
    var start = 0;
    var end;
    var index = 0;


    // 计算文件切片总数
    slices = Math.ceil(blob.size / BYTES_PER_CHUNK);
    totalSlices= slices;
    while(start < blob.size) {
    end = start + BYTES_PER_CHUNK;
    if(end > blob.size) {
    end = blob.size;
    }
    uploadFile(blob, index, start, end);
    start = end;
    index++;
    if ( index>=totalSlices )
        alert("jieshu");
        //location="reboot.htm";
    }
}

//上传文件
function uploadFile(blob, index, start, end) {
    var tagetUrl ="location:8087/uds/upload?Id=83&TaskUuid=aded4b65-e7e8-42bf-8f3f-aebf2aed9624&FileBeginPos=0&FileEndPos=26246025&AccessToken=AccessTokenString";
    var xhr;
    var fd;
    var chunk;  
    var sliceIndex=blob.name+index;
    console.log("sliceIndex:"+sliceIndex);
    chunk =blob.slice(start,end);//切割文件 
     console.log("chunk:"+chunk);
    fd = new FormData();
    fd.append("UpgradeFileName", chunk, sliceIndex);
    var xhr = new XMLHttpRequest();
    xhr.open('POST', tagetUrl, false);//false指同步上传，因为我的服务器内存较小，选择同步，如果追求速度，可以选择 //ture，异步上传
    xhr.send(fd);
    if((xhr.status >=200 && xhr.status < 300) || xhr.status == 304){
    setTimeout("",10);
    }else{
    uploadFile(blob, index, start, end);
    }
}
</script>

</head>
<body>

<table id="upload">
    <tr>
        <th width='180'>属性</th>
        <th>值</th>
    </tr>

    <tr>
        <td>上传文件</td>
        <td>
       <!--  <input type="file" multiple="" name="file" id="file" onchange="chenk();"> 
        <input type="file" multiple="" name="file" id="file" onchange="sendRequest();">
       </td>

        <input type="hidden" name="uploadURL" id = "uploadURL">
      <input type="hidden" name="resultId" id = "resultId">
       <input type="hidden" name="taskUuid" id = "taskUuid">  
    </tr>

</table>

<table id="trans_task">
    <tr>
        <th width='200'>本地文件</th>
        <th width='200'>FileServerGUID(不可重复)</th>
        <th width='200'>TaskGUID(TaskGUID=0时为新任务)</th>
        <th width='30'>状态</th>
        <th width='300'>上传进度</th>
    </tr>

</table>

</body>
</html> -->